broker = "redis://redisdb:6379/1"  # 任务队列
backend = "redis://redisdb:6379/2"  # 结果存储


# 设置代理人broker
broker_url = broker  # CELERY_BROKER_URL = broker
# 设置结果存储
result_backend = backend  # CELERY_RESULT_BACKEND = backend
# 自定义调度类，使用Django的ORM
beat_scheduler = (
    "django_celery_beat.schedulers:DatabaseScheduler"  # CELERY_BEAT_SCHEDULER
)
# # 关闭时区感知
DJANGO_CELERY_BEAT_TZ_AWARE = False
# celery beat配置（周期性任务设置）
CELERY_ENABLE_UTC = False
# 指定时区，默认是 UTC, 6.0
timezone = "Asia/Shanghai"  # CELERY_TIMEZONE = "Asia/Shanghai"
# 非常重要,有些情况下可以防止死锁
CELERYD_FORCE_EXECV = True
# 设置任务结果过期时间
result_expires = 60  # CELERY_RESULT_EXPIRES = 60
# 用户定义时区
# USE_TZ = False
# ======================================================================
# CELERY_HIJACK_ROOT_LOGGER = False
# # 开启重连
broker_connection_retry_on_startup = True
# celery 的 worker 执行多少个任务后进行重启操作
worker_max_tasks_per_child = 100  # CELERY_WORKER_MAX_TASKS_PER_CHILD = 100
# 并发worker数
worker_concurrency = 2  # CELERY_WORKER_CONCURRENCY = 20
# 单个任务的运行时间不超过此值
task_time_limit = 1200
# 任务发出后，经过一段时间还未收到acknowledge , 就将任务重新交给其他worker执行
worker_disable_rate_limits = False  # CELERY_DISABLE_RATE_LIMITS = True
# 任务预取功能，会尽量多拿 n 个，以保证获取的通讯成本可以压缩。
CELERY_PREFETCH_MULTIPLIER = 20
# 最大存取间隔
beat_max_loop_interval = 5
# celery beat配置（周期性任务设置）
# 使用redis作为中间件  定时任务调度器
# CELERY_BROKER_TRANSPORT = "redis"
# # =====================================================================
# 简体中文界面
# LANGUAGE_CODE = "zh-hans"
# 每个 worker 最多执行3个任务就会被销毁，可防止内存泄露
# worker_max_tasks_per_child = 3 # CELERYD_MAX_TASKS_PER_CHILD = 3
